package com.leoman.plz_p.presenter;


import com.leoman.plz_p.interfaces.ExamRecordView;
import com.leoman.plz_p.module.api.CourseApi;
import com.leoman.plz_p.module.api.ExamApi;
import com.leoman.plz_p.module.bean.BaseData;
import com.leoman.plz_p.module.bean.ExamRecordBean;
import com.leoman.plz_p.module.bean.MapData;
import com.leoman.plz_p.subscriber.ResponseSubscriber;
import com.leoman.plz_p.utils.UserHelper;

import cn.com.corelib.api.ResponseTransformer;
import cn.com.corelib.base.BasePresenter;

public class ExamRecordPresenter extends BasePresenter<ExamRecordView> {

    private CourseApi courseApi;
    private ExamApi examApi;

    @Override
    protected void onViewAttach() {
        super.onViewAttach();
        courseApi=getApi(CourseApi.class);
        examApi=getApi(ExamApi.class);
    }

    public void getExamRecord(){
        getView().showLoading();
        courseApi.getExamRecord(UserHelper.getToken())
                .compose(new ResponseTransformer<>(this.<BaseData<MapData<ExamRecordBean>>>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<BaseData<MapData<ExamRecordBean>>>(view) {
                    @Override
                    public void success(BaseData<MapData<ExamRecordBean>> mapDataBaseData) {
                        view.obtainExamRecord(mapDataBaseData.data);
                    }
                });
    }

    public void getExamIds(String examId){
        examApi.getExamIds(UserHelper.getToken(),examId).compose(new ResponseTransformer<>(this.<BaseData<MapData>>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<BaseData<MapData>>(view) {
                    @Override
                    public void success(BaseData<MapData> mapDataBaseData) {
                        view.obtainIds(mapDataBaseData.data.ids,mapDataBaseData.data);
                    }
                });
    }

    @Override
    public void onStart() {
        getExamRecord();
    }
}